<template>
  <div class="container">
    <div class="banner-container">
      <el-image
          src="/breed/introduction_background.jpg"
          alt="平台介绍背景图"
          class="banner-image"
      />
    </div>

    <div class="content-wrapper">
      <!-- 左侧导航栏 -->
      <div class="nav-container">
        <el-card class="nav-card">
          <div class="nav-header">
            <h1 class="nav-title">技术服务</h1>
          </div>
          <el-menu
              router
              :default-active="activeIndex"
              class="nav-menu"
              mode="vertical"
              @select="handleSelect"
          >
            <!-- 功能菌株筛选与创制 -->
            <el-sub-menu index="/ServiceIntroduction" class="function-menu">
              <template #title>
                <span class="menu-title">功能菌株筛选与创制</span>
              </template>
              <el-menu-item index="/ServiceIntroduction/Promotion">
                <span class="submenu-title multi-line">药用植物共生细菌分离鉴定及促生菌株筛选</span>
              </el-menu-item>
              <el-menu-item index="/ServiceIntroduction/Antagonism">
                <span class="submenu-title multi-line">药用植物病害菌分离鉴定及拮抗菌株筛选</span>
              </el-menu-item>
              <el-menu-item index="/ServiceIntroduction/Fertilizer">
                <span class="submenu-title">绿色微生物菌肥开发</span>
              </el-menu-item>
              <el-menu-item index="/ServiceIntroduction/Breeding">
                <span class="submenu-title">菌株选育</span>
              </el-menu-item>
            </el-sub-menu>

            <!-- 微生物菌株鉴定与保藏服务 -->
            <el-menu-item index="/ServiceIntroduction/IdentificationReserve">
              <template #title>
                <span class="menu-title">微生物菌株鉴定与保藏服务</span>
              </template>
            </el-menu-item>

            <!-- 菌株鉴定与保藏登记 -->
            <el-menu-item index="/ServiceIntroduction/FungiRegistration">
              <template #title>
                <span class="menu-title">菌株鉴定与保藏登记</span>
              </template>
            </el-menu-item>
          </el-menu>
        </el-card>
      </div>

      <!-- 右侧内容区 -->
      <div class="main-content">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue';
import { ElDivider } from 'element-plus';

export default {
  components: {
    ElDivider
  },
  setup() {
    const activeIndex = ref('/');

    const handleSelect = (index) => {
      activeIndex.value = index;
      console.log('Selected index:', index);
    };

    return {
      activeIndex,
      handleSelect
    };
  }
};
</script>

<style scoped>
/* 整体布局 */
.container {
  min-height: 100vh;
  min-width: 100%;
  padding-bottom: 30px;
}

.banner-container {
  width: 100%;
  max-height: 300px;
  overflow: hidden;
  margin-bottom: 2rem;
}

.banner-image {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.content-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%; /* 增加整体宽度 */
  margin: 0 auto;
}

@media (min-width: 1024px) {
  .content-wrapper {
    flex-direction: row;
    width: 100%;
    padding-left: 5%; /* 减少左侧整体留白到5% */
    padding-right: 5%; /* 减少右侧整体留白到5% */
    box-sizing: border-box;
  }
}

/* 左侧导航样式 */
.nav-container {
  width: 100%;
}

@media (min-width: 1024px) {
  .nav-container {
    width: 24rem; /* 增加导航栏宽度 */
    flex-shrink: 0;
    padding-right: 2rem; /* 稍微减少导航与内容之间的间距 */
  }
}

.nav-card {
  height: fit-content;
  border-radius: 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  padding: 2rem;
}

.nav-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 3px solid #13675b;
}

.nav-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: #13675b;
}

.nav-menu {
  font-size: 1.875rem;
  border: none;
}

/* 主菜单项样式 */
.el-menu-item {
  font-size: 1.875rem;
  height: 3.75rem;
  line-height: 3.75rem;
  border-bottom: 1px solid #f0f0f0;
}

.el-menu-item:last-child {
  border-bottom: none;
}

.el-menu-item span {
  font-size: 1.875rem;
}

.menu-title {
  font-size: 1.125rem;
  font-weight: 500;
}

/* 子菜单样式 */
.submenu-title {
  font-size: 1rem;
  font-weight: normal;
}

/* 多行子菜单样式 */
.submenu-title.multi-line {
  white-space: normal;
  line-height: 1.4;
  padding: 0.5rem 0;
  display: block;
}

/* 子菜单项样式 */
:deep(.el-sub-menu .el-menu-item) {
  height: auto; /* 改为自动高度以适应多行文本 */
  line-height: normal;
  min-width: 0;
  padding-left: 40px !important; /* 减少子菜单项的左内边距 */
  padding-top: 0.5rem !important;
  padding-bottom: 0.5rem !important;
}

/* 为多行菜单项设置固定高度 */
:deep(.el-sub-menu .el-menu-item .multi-line) {
  min-height: 3rem;
  display: flex;
  align-items: center;
}

:deep(.el-sub-menu .el-menu-item span) {
  font-size: 1rem;
  line-height: 1.4;
}

:deep(.el-sub-menu__title) {
  font-size: 1.125rem;
  font-weight: 500;
  height: 3.75rem;
  line-height: 3.75rem;
  border-bottom: 1px solid #f0f0f0;
  padding-left: 20px !important; /* 减少子菜单标题的左内边距 */
}

:deep(.el-sub-menu .el-menu) {
  background-color: #fafafa;
}

:deep(.el-sub-menu .el-menu-item.is-active) {
  background-color: #e6f7f4;
  color: #13675b;
}

/* 右侧内容区 */
.main-content {
  flex: 1;
}

/* 响应式调整 */
@media (max-width: 1024px) {
  .nav-menu,
  .el-menu-item,
  .el-menu-item span {
    font-size: 1.875rem;
  }
}

@media (max-width: 768px) {
  .nav-menu,
  .el-menu-item,
  .el-menu-item span {
    font-size: 1.875rem;
  }

  :deep(.el-sub-menu .el-menu-item) {
    padding-left: 30px !important; /* 移动端也相应减少 */
  }

  :deep(.el-sub-menu__title) {
    padding-left: 15px !important; /* 移动端也相应减少 */
  }
}
</style>